package com.qf.ts.platform.front.service.impl;

import com.qf.ts.platform.front.domain.Car;
import com.qf.ts.platform.front.mapper.CarMapper;
import com.qf.ts.platform.front.mapper.UserMapper;
import com.qf.ts.platform.front.service.CarService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {

    @Autowired
    private CarMapper carMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public int addCar(Car car, Integer uid) {

        carMapper.addCar(car);

        int result = carMapper.addMidTable(uid, car.getId());

        return result;
    }

    @Override
    public List<Car> showCars(Integer uid) {
        return carMapper.findCars(uid);
    }

    @Override
    public Car showCarDetail(Integer cid) {
        return carMapper.findCar(cid);
    }

    @Override
    public int deleteCar(String uid,Integer cid) {

        int newUid = userMapper.getIdByUuid(uid);

        carMapper.deleteUserCar(newUid,cid);

        return carMapper.deleteCar(cid);
    }

    @Override
    public Integer updateCar(Car car) {
        return carMapper.updateCar(car);
    }

}
